package com.ruoyi.project.data.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.service.PermissionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.data.service.MainIndexService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页统计
 */
@RestController
@RequestMapping("/dashboard")
public class MainIndexController extends BaseController {

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private MainIndexService mainIndexService;

    /**
     * @Description  获取首页头部信息
     * @params  * @param
     * @ return  com.ruoyi.framework.web.domain.AjaxResult
     * @Author hh
     * Date create by 2020/3/29 20:47
     */
    @GetMapping(value = "/getTopData")
    public AjaxResult  getTopData(){
        Map<String,Object> param=new HashMap<>();
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        param.put("stationId", stationId);
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        param.put("areas",areas);
        param.put("managementCharacters",managementCharacters);
        return  AjaxResult.success(mainIndexService.selectTopData(param));
    }

    @GetMapping(value = "/getMonthYdData")
    public AjaxResult  getMonthYdData(){
        Map<String,String> param=new HashMap<>();
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        param.put("stationId", String.valueOf(stationId));
        if(String.valueOf(stationId).equals("null")){
            param.put("stationId", null);
        }
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        param.put("areas",areas);
        param.put("managementCharacters",managementCharacters);

        return  AjaxResult.success(mainIndexService.getMonthYdData(param));
    }

    /**
     * 获取月度异常汇总
     * @return
     */
    @GetMapping(value = "/getMonthYdycdata")
    public AjaxResult getMonthYdycdata(){
        Map<String,String> param=new HashMap<>();
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        param.put("stationId", String.valueOf(stationId));
        if(String.valueOf(stationId).equals("null")){
            param.put("stationId", null);
        }
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        param.put("areas",areas);
        param.put("managementCharacters",managementCharacters);
        return  AjaxResult.success(mainIndexService.selectMonthYdycdata(param));
    }


    /**
     * 查询场站排行
     * @return
     */
    @RequestMapping(value = "/selectStationSortData")
    public  AjaxResult selectStationSortData(){
        Map<String,String> param=new HashMap<>();
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        param.put("stationId", String.valueOf(stationId));
        if(String.valueOf(stationId).equals("null")){
            param.put("stationId", null);
        }
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        param.put("areas",areas);
        param.put("managementCharacters",managementCharacters);
        return  AjaxResult.success(mainIndexService.selectStationSortData(param));
    }
}
